/**********************************************************************
* Filename: Membro.java
* Created: 2012/04/23
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.copaPaises.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Membro
{
	public static Set<Membro> allInstances = new HashSet<Membro>();
	
	private int minuto_entrada;
	private int minuto_saida;
	private Equipa equipa;
	private Jogador jogador;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Membro()
	{
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param minuto_entrada the minuto_entrada to initialize
	* @param minuto_saida the minuto_saida to initialize
	* @param equipa the equipa to initialize
	* @param jogador the jogador to initialize
	**********************************************************************/
	public Membro(int minuto_entrada, int minuto_saida, Equipa equipa, Jogador jogador)
	{
		this.minuto_entrada = minuto_entrada;
		this.minuto_saida = minuto_saida;
		this.equipa = equipa;
		this.jogador = jogador;
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the minuto_entrada of the membro
	**********************************************************************/
	public int minuto_entrada()
	{
		return minuto_entrada;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param minuto_entrada the minuto_entrada to set
	**********************************************************************/
	public void setMinuto_entrada(int minuto_entrada)
	{
		this.minuto_entrada = minuto_entrada;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the minuto_saida of the membro
	**********************************************************************/
	public int minuto_saida()
	{
		return minuto_saida;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param minuto_saida the minuto_saida to set
	**********************************************************************/
	public void setMinuto_saida(int minuto_saida)
	{
		this.minuto_saida = minuto_saida;
	}
	
	/**********************************************************************
	* ASSOCIATIVE2MEMBER getter for Membro[*] <-> Equipa[1]
	* @return the equipa of the membro
	**********************************************************************/
	public Equipa equipa()
	{
		return equipa;
	}
	
	/**********************************************************************
	* ASSOCIATIVE2MEMBER setter for Membro[*] <-> Equipa[1]
	* @param equipa the equipa to set
	**********************************************************************/
	public void setEquipa(Equipa equipa)
	{
		this.equipa = equipa;
	}
	
	/**********************************************************************
	* ASSOCIATIVE2MEMBER getter for Membro[*] <-> Jogador[1]
	* @return the jogador of the membro
	**********************************************************************/
	public Jogador jogador()
	{
		return jogador;
	}
	
	/**********************************************************************
	* ASSOCIATIVE2MEMBER setter for Membro[*] <-> Jogador[1]
	* @param jogador the jogador to set
	**********************************************************************/
	public void setJogador(Jogador jogador)
	{
		this.jogador = jogador;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Membro[1] <-> Cartao[0..2]
	* @return the cartoes of the membro
	**********************************************************************/
	public Set<Cartao> cartoes()
	{
		Set<Cartao> result = new HashSet<Cartao>();
		for (Cartao x : Cartao.allInstances)
			if (x.membro()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Membro[1] <-> Cartao[0..2]
	* @param cartoes the cartoes to set
	**********************************************************************/
	public void setCartoes(Set<Cartao> cartoes)
	{
		for (Cartao x : cartoes)
			x.setMembro(this);
	}
	
	/**********************************************************************
	* ONE2MANY getter for Membro[1] <-> Golo[*]
	* @return the golos of the marcador
	**********************************************************************/
	public Set<Golo> golos()
	{
		Set<Golo> result = new HashSet<Golo>();
		for (Golo x : Golo.allInstances)
			if (x.marcador()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Membro[1] <-> Golo[*]
	* @param golos the golos to set
	**********************************************************************/
	public void setGolos(Set<Golo> golos)
	{
		for (Golo x : golos)
			x.setMarcador(this);
	}
	
	/* (non-Javadoc)
	* @see java.lang.Object#toString()
	*/
	@Override
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Membro [minuto_entrada=" + minuto_entrada + ", minuto_saida=" + minuto_saida + ", equipa=" + equipa + ", jogador=" + jogador + "]\n";
	}
	
}
